package com.zh.work.service.platform.merch.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zh.work.dao.platform.merch.ChangeMerchAccountMapper;
import com.zh.work.dao.platform.merch.ChangeMerchInfoMapper;
import com.zh.work.dao.platform.merch.ChangeMerchRateMapper;
import com.zh.work.entity.merch.ChangeMerchAccountEntity;
import com.zh.work.entity.merch.ChangeMerchInfoEntity;
import com.zh.work.entity.merch.ChangeMerchRateEntity;
import com.zh.work.service.platform.merch.ChangeMerchInfoService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * code is far away from bug with the animal protecting
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃代码无BUG！
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 *
 * @Description: 商户资料变更记录业务逻辑实现层
 * @Author: Li.HuiNeng
 * @Create in: 2019/09/05
 * @Version: 1.0.1
 */
@Service
public class ChangeMerchInfoServiceImpl extends ServiceImpl<ChangeMerchInfoMapper, ChangeMerchInfoEntity> implements ChangeMerchInfoService {

    @Autowired
    private ChangeMerchInfoMapper changeMerchInfoMapper;


    @Autowired
    private ChangeMerchRateMapper changeMerchRateMapper;

    @Autowired
    private ChangeMerchAccountMapper changeMerchAccountMapper;


    @Override
    public IPage<ChangeMerchInfoEntity> selectChangeMerchPages(Page<ChangeMerchInfoEntity> page, ChangeMerchInfoEntity changeMerchInfoEntity) {
        return this.changeMerchInfoMapper.selectPage(
                page,
                new QueryWrapper<ChangeMerchInfoEntity>().lambda()
                        .like(StringUtils.isNotEmpty(changeMerchInfoEntity.getMerchNo()), ChangeMerchInfoEntity::getMerchNo, changeMerchInfoEntity.getMerchNo())
                        .like(StringUtils.isNotEmpty(changeMerchInfoEntity.getMerchName()), ChangeMerchInfoEntity::getMerchName, changeMerchInfoEntity.getMerchName())
                        .eq(Objects.nonNull(changeMerchInfoEntity.getAuditStatus()), ChangeMerchInfoEntity::getAuditStatus, changeMerchInfoEntity.getAuditStatus())
                        .between(ObjectUtils.allNotNull(changeMerchInfoEntity.getStartDate(), changeMerchInfoEntity.getEndDate()),
                                ChangeMerchInfoEntity::getAddTime, changeMerchInfoEntity.getStartDate(), changeMerchInfoEntity.getEndDate())
        );
    }

    @Override
    public IPage<ChangeMerchRateEntity> selectChangeMerchPages(Page<ChangeMerchRateEntity> page, ChangeMerchRateEntity changeMerchRateEntity) {
        return this.changeMerchRateMapper.selectPage(
                page,
                new QueryWrapper<ChangeMerchRateEntity>().lambda()
                        .like(StringUtils.isNotEmpty(changeMerchRateEntity.getMerchNo()), ChangeMerchRateEntity::getMerchName, changeMerchRateEntity.getMerchNo())
                        .like(StringUtils.isNotEmpty(changeMerchRateEntity.getMerchName()), ChangeMerchRateEntity::getMerchName, changeMerchRateEntity.getMerchName())
                        .eq(Objects.nonNull(changeMerchRateEntity.getAuditStatus()), ChangeMerchRateEntity::getAuditStatus, changeMerchRateEntity.getAuditStatus())
                        .between(ObjectUtils.allNotNull(changeMerchRateEntity.getStartDate(), changeMerchRateEntity.getEndDate()),
                                ChangeMerchRateEntity::getAddTime, changeMerchRateEntity.getStartDate(), changeMerchRateEntity.getEndDate())
        );
    }

    @Override
    public IPage<ChangeMerchAccountEntity> selectChangeMerchPages(Page<ChangeMerchAccountEntity> page, ChangeMerchAccountEntity changeMerchAccountEntity) {
        return this.changeMerchAccountMapper.selectPage(
                page,
                new QueryWrapper<ChangeMerchAccountEntity>().lambda()
                        .like(StringUtils.isNotEmpty(changeMerchAccountEntity.getMerchNo()), ChangeMerchAccountEntity::getMerchName, changeMerchAccountEntity.getMerchNo())
                        .like(StringUtils.isNotEmpty(changeMerchAccountEntity.getMerchName()), ChangeMerchAccountEntity::getMerchName, changeMerchAccountEntity.getMerchName())
                        .eq(Objects.nonNull(changeMerchAccountEntity.getAuditStatus()), ChangeMerchAccountEntity::getAuditStatus, changeMerchAccountEntity.getAuditStatus())
                        .between(ObjectUtils.allNotNull(changeMerchAccountEntity.getStartDate(), changeMerchAccountEntity.getEndDate()),
                                ChangeMerchAccountEntity::getAddTime, changeMerchAccountEntity.getStartDate(), changeMerchAccountEntity.getEndDate())
        );
    }
}
